package com.hzcx.app.simplechat.ui.chat.dialog;

import android.content.Context;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.hzcx.app.simplechat.R;
import com.hzcx.app.simplechat.base.BaseDialog;
import com.hzcx.app.simplechat.ui.chat.event.ChatShareUserEvent;
import com.hzcx.app.simplechat.ui.friend.bean.FriendBean;
import com.hzcx.app.simplechat.ui.friend.bean.FriendCityBean;
import com.hzcx.app.simplechat.ui.group.bean.GroupInfoBean;
import com.hzcx.app.simplechat.ui.user.bean.UserInfoBean;
import com.hzcx.app.simplechat.util.empty.EmptyUtils;
import com.hzcx.app.simplechat.util.glide.GlideUtils;
import com.hzcx.app.simplechat.view.imageview.RoundImageView;

import org.greenrobot.eventbus.EventBus;

import butterknife.BindView;

/**
 * 分享名片弹窗
 */
public class ChatShareUserDialog extends BaseDialog {
    @BindView(R.id.iv_head)
    RoundImageView ivHead;
    @BindView(R.id.tv_nick_name)
    TextView tvNickName;
    @BindView(R.id.tv_share_name)
    TextView tvShareName;
    @BindView(R.id.et_share_remark)
    EditText etShareRemark;
    @BindView(R.id.tv_cancel)
    TextView tvCancel;
    @BindView(R.id.tv_send)
    TextView tvSend;

    private UserInfoBean userInfoBean;
    private GroupInfoBean groupInfoBean;
    private FriendCityBean bean;
    private OnChatShareUserListener listener;

    public ChatShareUserDialog(@NonNull Context context, UserInfoBean userInfoBean, FriendCityBean bean,OnChatShareUserListener listener) {
        super(context);
        this.userInfoBean = userInfoBean;
        this.bean = bean;
        this.listener=listener;
    }
    public ChatShareUserDialog(@NonNull Context context, GroupInfoBean groupInfoBean, FriendCityBean bean, OnChatShareUserListener listener) {
        super(context);
        this.groupInfoBean = groupInfoBean;
        this.bean = bean;
        this.listener=listener;
    }

    @Override
    public int getLayout() {
        return R.layout.dialog_chat_share_user;
    }

    @Override
    public void initPresenter() {

    }

    @Override
    public void initView() {

        if (userInfoBean!=null){
            GlideUtils.loadImg(context, userInfoBean.getAvatar(), ivHead);
            tvNickName.setText(userInfoBean.getNickname());
        }else {
            GlideUtils.loadImg(context, groupInfoBean.getGroup_image(), ivHead);
            tvNickName.setText(groupInfoBean.getGroup_name());
        }
        if (EmptyUtils.isEmpty(bean.getRemarks_name())) {
            tvShareName.setText("[个人名片]" + bean.getNickname());
        } else {
            tvShareName.setText("[个人名片]" + bean.getRemarks_name());
        }

        tvCancel.setOnClickListener(view -> dismiss());

        tvSend.setOnClickListener(view -> {
            if(listener!=null){
                listener.shareUser(bean,etShareRemark.getText().toString());
            }
            dismiss();
        });
    }

    @Override
    public void initData() {

    }

    public interface OnChatShareUserListener {
        void shareUser(FriendCityBean bean,String remark);
    }
}
